const Mock = require("mockjs");
const getQuestionList = require("./data/getQuestionList");
const getComponentList = require("./data/getComponentList");

const Random = Mock.Random;

module.exports = [
  {
    url: "/api/question/:id", //获取单个问卷
    method: "get",
    response() {
      return {
        errno: 0,
        data: {
          id: Random.id(),
          title: Random.ctitle(),
          desc: "问卷描述",
          js: "",
          css: "",
          isPublished: true,
          componentList: getComponentList(),
        },
        // errno:1002,
        // msg:'错误'
      };
    },
  },
  {
    url: "/api/question", //创建问卷
    method: "post",
    response() {
      return {
        errno: 0,
        data: {
          id: Random.id(),
        },
      };
    },
  },
  {
    url: "/api/question", //查询问卷列表
    method: "get",
    response(ctx) {
      const url = ctx.url;
      const isDeleted = url.indexOf("isDeleted=true") >= 0;
      const isStar = url.indexOf("isStar=true") >= 0;
      return {
        errno: 0,
        data: {
          list: getQuestionList({ isDeleted, isStar }), //当前页
          total: 100, //总数，分页
        },
      };
    },
  },
  {
    url: "/api/question/:id", //更新问卷
    method: "patch",
    response(ctx) {
      return {
        errno: 0,
      };
    },
  },
  {
    url: `/api/question/duplicate/:id`, // 修改、更新问卷
    method: "post",
    response() {
      return {
        errno: 0,
        data: {
          id: Random.id(),
        },
      };
    },
  },
  {
    url: `/api/question`, // 批量彻底删除
    method: "delete",
    response() {
      return {
        errno: 0,
      };
    },
  },
];
